<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-2">
            <div class="ibox ibox-body">
                <div class="ibox-content">
                    <div id="orgTree"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        getTreeData();
    });

    function getTreeData() {
        $.ajax({
            type: "GET",
            url: jsctx + "/tenant/org/orgTreeUserData",
            success: function (tree) {
                loadTree(tree);
            }
        });
    }

    function loadTree(tree) {
        $('#orgTree').jstree({
            'core': {
                'data': tree
            },
            "plugins": ["search"]
        });
        $('#orgTree').jstree().open_all();
    }

    $('#orgTree').on("changed.jstree", function (e, data) {
        var type = "${type}";

        //只返回用户
        if (data.node.id != -1 && data.node.id > 1000000) {
            if (type == 1) {
                parent.loadApprover(data.node.id, data.node.text);
            } else if (type == 2) {
                parent.loadCc(data.node.id, data.node.text);
            } else {
                return
            }

            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    });
</script>
</body>
</html>